package a66weding.com.jiehuntong.activity.home;

import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Paint;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.CompoundButton;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RadioButton;
import android.widget.TextView;

import com.andview.refreshview.XRefreshView;
import com.andview.refreshview.XRefreshViewFooter;
import com.andview.refreshview.XRefreshViewHeader;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import a66weding.com.jiehuntong.R;
import a66weding.com.jiehuntong.activity.LoginActivity;
import a66weding.com.jiehuntong.activity.home.hotel.shop.HomeProductdetailActivity;
import a66weding.com.jiehuntong.activity.me.MeShoppingCartActivity;
import a66weding.com.jiehuntong.application.GlobalApplication;
import a66weding.com.jiehuntong.beans.CateguryGridViewBean;
import a66weding.com.jiehuntong.beans.CommonResultBean;
import a66weding.com.jiehuntong.beans.ErrorBean;
import a66weding.com.jiehuntong.beans.HomeBotomListBean;
import a66weding.com.jiehuntong.beans.HttpRequestBean;
import a66weding.com.jiehuntong.beans.SuccessBean;
import a66weding.com.jiehuntong.common.CommonAdapter;
import a66weding.com.jiehuntong.common.MyViewHolder;
import a66weding.com.jiehuntong.common.utils.CUtils;
import a66weding.com.jiehuntong.common.utils.Tools;
import a66weding.com.jiehuntong.http.HttpHandleUtil;
import a66weding.com.jiehuntong.http.OnNetResultListener;
import a66weding.com.jiehuntong.http.RequestCode;
import a66weding.com.jiehuntong.view.ConfirmLoginDialog;
/**
 * 作用:首页的---婚品购置界面
 * Created by Administrator on 2016/8/1.
 */
public class HomeWedShoppingActivity extends BaseHomeActivity implements View.OnClickListener, CompoundButton.OnCheckedChangeListener, OnNetResultListener {
    private LinearLayout mBackLay;
    private TextView mBackContentTv;
    private TextView mHeaderTitleTv;
    private ImageView mRightFuncIv;
    private LinearLayout mProgressLay;
    private ViewGroup mContentLay;
    private LinearLayout mNoNetLay;
    private LinearLayout mContentTitleLay;
    private TextView mDefaultorderTv;
    private TextView mCollectOrderTv;
    private LinearLayout mPriceOrderLay;
    private ImageView mPriceOrderIv;
    private TextView mPriceTv;
    private GridView mCommodityGv;
    private RadioButton wedshopRbtn;
    private RadioButton wedshoeRbtn;
    private RadioButton wedlifeRbtn;
    private RadioButton housethingRbtn;
    private RadioButton jewelryRbtn;
    private RadioButton babythingRbtn;
    private RadioButton mSet1Rbtn;
    private RadioButton mSet2Rbtn;
    private RadioButton mSet3Rbtn;
    private RadioButton mSet4Rbtn;
    private PopupWindow mAreaPop;
    private CommonAdapter<HomeBotomListBean.DataBean> mAdapter;
    private int categoryId = 1087;
    private List<HomeBotomListBean.DataBean> bottomListdata = new ArrayList<HomeBotomListBean.DataBean>();
    private boolean isPriceUp;//默认降序
    private String title;
    private CateguryGridViewBean categuryData;
    private List<CateguryGridViewBean.DataBean> categuryListdata;
    private HashMap<String, Integer> categryMap = new HashMap<String, Integer>();
    private int currentIndex;
    private boolean islogin;
    private XRefreshView xRefreshView;
    private static int pageIndex = 1;
    private long lastRefreshTime = System.currentTimeMillis();
    private int mCurrentOrder=5;
    private int REQUEST_LOGIN_CODE=3333;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_wed_shopping);
        ((GlobalApplication) getApplication()).getActivityManager().addActivity("HomeWedShoppingActivity", this);

        Intent intent = getIntent();
        if (intent != null) {
            title = intent.getStringExtra("title");
            categoryId = intent.getIntExtra("categoryId", 1087);
            Bundle extras = intent.getExtras();
            if (extras != null) {
                categuryData = (CateguryGridViewBean) extras.get("data");
                categuryListdata = categuryData.getData();
                for (int i = 0; i < categuryListdata.size(); i++) {
                    CateguryGridViewBean.DataBean dataBean = categuryListdata.get(i);
                    if ("婚纱礼服".equals(dataBean.getNvc_Name())) {
                        categryMap.put("婚纱礼服", dataBean.getI_Id());
                    } else if ("珠宝配饰".equals(dataBean.getNvc_Name())) {
                        categryMap.put("珠宝配饰", dataBean.getI_Id());
                    } else if ("家用电器".equals(dataBean.getNvc_Name())) {
                        categryMap.put("家用电器", dataBean.getI_Id());
                    } else if ("护肤美体".equals(dataBean.getNvc_Name())) {
                        categryMap.put("护肤美体", dataBean.getI_Id());
                    } else if ("运动户外".equals(dataBean.getNvc_Name())) {
                        categryMap.put("运动户外", dataBean.getI_Id());
                    } else if ("婚礼用品".equals(dataBean.getNvc_Name())) {
                        categryMap.put("婚礼用品", dataBean.getI_Id());
                    } else if ("母婴生活".equals(dataBean.getNvc_Name())) {
                        categryMap.put("母婴生活", dataBean.getI_Id());
                    } else if ("厨卫用品".equals(dataBean.getNvc_Name())) {
                        categryMap.put("厨卫用品", dataBean.getI_Id());
                    } else if ("家居家装".equals(dataBean.getNvc_Name())) {
                        categryMap.put("家居家装", dataBean.getI_Id());
                    }
                }
            }
        }
        initview();
        getListdata(categoryId, 1, mCurrentOrder);
        islogin = ((GlobalApplication) getApplication()).isLogin();
    }
    private void initview() {
        mBackLay = (LinearLayout) findViewById(R.id.llay_header_back);
        mBackContentTv = (TextView) findViewById(R.id.tv_header_backcontent);
        mHeaderTitleTv = (TextView) findViewById(R.id.tv_header_title);
        mRightFuncIv = (ImageView) findViewById(R.id.iv_search_red);
        mProgressLay = (LinearLayout) findViewById(R.id.progressLay);
        mNoNetLay = (LinearLayout) findViewById(R.id.mNoNetLay);
        mContentTitleLay = (LinearLayout) findViewById(R.id.lay_content_title);
        xRefreshView = (XRefreshView) findViewById(R.id.shoplist_xrefreshview);
        mDefaultorderTv = (TextView) findViewById(R.id.llay_defaultorder);
        mCollectOrderTv = (TextView) findViewById(R.id.tv_collectorder);
        mPriceOrderLay = (LinearLayout) findViewById(R.id.llay_priceorder);
        mPriceOrderIv = (ImageView) findViewById(R.id.iv_priceorder);
        mPriceTv = (TextView) findViewById(R.id.tv_price);
        mContentLay = mCommodityGv = (GridView) findViewById(R.id.gv_home_wed_shopping);
        if (categuryData != null) {
            mHeaderTitleTv.setText(title);
            if ("婚品购置".equals(title)) {
                mBackContentTv.setText("首页");
            } else {
                mBackContentTv.setText("分类");
            }
        }
        mRightFuncIv.setImageResource(R.mipmap.cart);
        mDefaultorderTv.setTextColor(getResources().getColor(R.color.colorMainRed));
        mDefaultorderTv.setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(R.mipmap.arror_red_down), null);
        mBackLay.setOnClickListener(this);
        mDefaultorderTv.setOnClickListener(this);
        mCollectOrderTv.setOnClickListener(this);
        mPriceOrderLay.setOnClickListener(this);
        mRightFuncIv.setOnClickListener(this);
    }
    /**
     * order:排序 0按上架时间降序排序 1按销量排序 2按收藏数量排序 3按价格数量升序 4按价格数量降序
     * @param categoryId
     * @param pageIndex
     * @param order
     */
    private void getListdata(int categoryId, int pageIndex, int order) {
        String url = RequestCode.get_ProductDressList;
        url += "&pageIndex=" + pageIndex + "&category=" + categoryId + "&order=" + order;
        HttpRequestBean httpRequestBean = new HttpRequestBean(RequestCode.GETREQUEST, url, this, HomeBotomListBean.class, RequestCode.get_ProductDressList);
        HttpHandleUtil.executeCommonGet(this, httpRequestBean);
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if(hasFocus){// 窗口获取焦点（需要判断窗口第一次获取焦点）
            int count = xRefreshView.getChildCount();
            if(count == 3){
                if(xRefreshView.getChildAt(0) instanceof XRefreshViewHeader){
                    XRefreshViewHeader headerView = (XRefreshViewHeader)xRefreshView.getChildAt(0);
                    headerView.getChildAt(0).setBackgroundColor(getResources().getColor(R.color.colorMainBack));
                }
                if(xRefreshView.getChildAt(2) instanceof XRefreshViewFooter){
                    XRefreshViewFooter footerView = (XRefreshViewFooter)xRefreshView.getChildAt(2);
                    footerView.getChildAt(0).setBackgroundColor(getResources().getColor(R.color.colorMainBack));
                }
            }
        }
    }

    /**
     * 界面销毁调用的方法
     */
    @Override
    protected void onDestroy() {
        super.onDestroy();
        resetPageIndex();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.llay_header_back: //点击返回，返回到上一级界面
                finish();

                break;
            case R.id.llay_defaultorder: //默认
                if (mAreaPop != null) {
                    mAreaPop.dismiss();
                    mAreaPop = null;
                    mDefaultorderTv.setTextColor(getResources().getColor(R.color.colorFontGray1));
                }
                mDefaultorderTv.setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(R.mipmap.arror_red_down), null);
                mCollectOrderTv.setTextColor(getResources().getColor(R.color.colorFontGray1));
                mPriceTv.setTextColor(getResources().getColor(R.color.colorFontGray1));
                freshTextview((TextView) v);
                showOrderPopupWindow(v);

                break;
            case R.id.tv_collectorder: //收藏最多
                mPriceTv.setTextColor(getResources().getColor(R.color.colorFontGray1));
                mPriceTv.setTextColor(getResources().getColor(R.color.colorFontGray1));
                mPriceOrderIv.setBackgroundResource(R.mipmap.order_normal);
                mCurrentOrder = 2;
                freshTextview((TextView) v);
                notifyViewLay(LOADINGDATA);
                switch (currentIndex) {
                    case 0:

                    case 1:

                    case 2:

                    case 3:

                    case 4:

                    case 5:

                    case 6:

                    case 7:

                    case 8:

                    case 9:
                        resetPageIndex();
                        Tools.showDialog(this);
                        getListdata(categoryId, pageIndex, 2);
                        break;
                }


                break;
            case R.id.llay_priceorder: //价格
                mPriceTv.setTextColor(getResources().getColor(R.color.colorMainRed));
                mCollectOrderTv.setTextColor(getResources().getColor(R.color.colorFontGray1));
                if (isPriceUp) {
                    notifyViewLay(LOADINGDATA);
                    mCurrentOrder = 4;
                    resetPageIndex();
                    getListdata(categoryId, pageIndex, 4);
                    mPriceOrderIv.setBackgroundResource(R.mipmap.order_down);
                    isPriceUp = false;
                } else {
                    notifyViewLay(LOADINGDATA);
                    resetPageIndex();
                    mCurrentOrder = 3;
                    getListdata(categoryId, pageIndex, 3);
                    mPriceOrderIv.setBackgroundResource(R.mipmap.order_up);
                    isPriceUp = true;
                }

                break;
            case R.id.rbtn_defaultorder: //婚纱礼服
                if (wedshopRbtn.isChecked()) {
                    mCurrentOrder = 5;
                    notifyViewLay(LOADINGDATA);
                    categoryId = categryMap.get("婚纱礼服");
                    resetPageIndex();
                    Tools.showDialog(this);
                    getListdata(categoryId, pageIndex, 0);

                }
                mHeaderTitleTv.setText("婚纱礼服");
                if (mAreaPop != null) {
                    mAreaPop.dismiss();
                }

                break;
            case R.id.rbtn_collectorder: //珠宝配饰
                if (wedshoeRbtn.isChecked()) {
                    mCurrentOrder = 5;
                    notifyViewLay(LOADINGDATA);
                    categoryId = categryMap.get("珠宝配饰");
                    resetPageIndex();
                    Tools.showDialog(this);
                    getListdata(categoryId, pageIndex, 0);

                }
                mHeaderTitleTv.setText("珠宝配饰");
                if (mAreaPop != null) {
                    mAreaPop.dismiss();
                }

                break;
            case R.id.rbtn_newreleasectorder: //家用电器
                if (wedlifeRbtn.isChecked()) {
                    notifyViewLay(LOADINGDATA);
                    mCurrentOrder = 5;
                    categoryId = categryMap.get("家用电器");
                    resetPageIndex();
                    Tools.showDialog(this);
                    getListdata(categoryId, pageIndex, 0);

                }
                mHeaderTitleTv.setText("家用电器");
                if (mAreaPop != null) {
                    mAreaPop.dismiss();
                }

                break;
            case R.id.rbtn_priceuporder: //护肤美体
                if (housethingRbtn.isChecked()) {
                    notifyViewLay(LOADINGDATA);
                    mCurrentOrder = 5;
                    categoryId = categryMap.get("护肤美体");
                    resetPageIndex();
                    Tools.showDialog(this);
                    getListdata(categoryId, pageIndex, 0);

                }
                mHeaderTitleTv.setText("护肤美体");
                if (mAreaPop != null) {
                    mAreaPop.dismiss();
                }

                break;
            case R.id.rbtn_priceorder: //运动户外
                if (jewelryRbtn.isChecked()) {
                    notifyViewLay(LOADINGDATA);
                    mCurrentOrder = 5;
                    categoryId = categryMap.get("运动户外");
                    resetPageIndex();
                    Tools.showDialog(this);
                    getListdata(categoryId, pageIndex, 0);

                }
                mHeaderTitleTv.setText("运动户外");
                if (mAreaPop != null) {
                    mAreaPop.dismiss();
                }

                break;
            case R.id.rbtn_third_right: //婚礼用品
                if (babythingRbtn.isChecked()) {
                    notifyViewLay(LOADINGDATA);
                    mCurrentOrder = 5;
                    categoryId = categryMap.get("婚礼用品");
                    resetPageIndex();
                    Tools.showDialog(this);
                    getListdata(categoryId, pageIndex, 0);
                }
                mHeaderTitleTv.setText("婚礼用品");
                if (mAreaPop != null) {
                    mAreaPop.dismiss();
                }

                break;
            case R.id.rbtn_product_1: //母婴生活
                if (mSet1Rbtn.isChecked()) {
                    notifyViewLay(LOADINGDATA);
                    mCurrentOrder = 5;
                    categoryId = categryMap.get("母婴生活");
                    resetPageIndex();
                    Tools.showDialog(this);
                    getListdata(categoryId, pageIndex, 4);
                }
                mHeaderTitleTv.setText("母婴生活");
                if (mAreaPop != null) {
                    mAreaPop.dismiss();
                }

                break;
            case R.id.rbtn_product_2: //厨卫用品
                if (mSet2Rbtn.isChecked()) {
                    notifyViewLay(LOADINGDATA);
                    mCurrentOrder = 5;
                    categoryId = categryMap.get("厨卫用品");
                    resetPageIndex();
                    Tools.showDialog(this);
                    getListdata(categoryId, pageIndex, 4);
                }
                mHeaderTitleTv.setText("厨卫用品");
                if (mAreaPop != null) {
                    mAreaPop.dismiss();
                }

                break;
            case R.id.rbtn_product_3: //家居家装
                if (mSet3Rbtn.isChecked()) {
                    notifyViewLay(LOADINGDATA);
                    mCurrentOrder = 5;
                    categoryId = categryMap.get("家居家装");
                    resetPageIndex();
                    Tools.showDialog(this);
                    getListdata(categoryId, pageIndex, 4);
                }
                mHeaderTitleTv.setText("家居家装");
                if (mAreaPop != null) {
                    mAreaPop.dismiss();
                }

                break;
            case R.id.iv_search_red: //购物车
                if (islogin) {
                    Intent intent = new Intent(this, MeShoppingCartActivity.class);
                    startActivity(intent);
                } else {
                    showLoginDialog();
                }
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode==REQUEST_LOGIN_CODE&&resultCode==LoginActivity.LOGIN_OK){
            Intent intent = new Intent(this, MeShoppingCartActivity.class);
            startActivity(intent);
        }
    }

    @Override
    public void onSucess(SuccessBean sucessbean) {
        Object data = sucessbean.getData();
        notifyViewLay(HAVEDATA);
        Tools.dismissWaitDialog();
        if (data instanceof CommonResultBean) {
        } else if (data instanceof HomeBotomListBean) {
            if (mAreaPop != null) {
                mAreaPop.dismiss();
            }
            xRefreshView.stopRefresh();
            xRefreshView.stopLoadMore();
            lastRefreshTime = xRefreshView.getLastRefreshTime();
            HomeBotomListBean databean = (HomeBotomListBean) data;
            initRefreshView();
            if (pageIndex > 1) {
                List<HomeBotomListBean.DataBean> dataLoad = databean.getData();
                bottomListdata.addAll(dataLoad);
                if (mAdapter != null) {
                    mAdapter.notifyDataSetChanged();
                }
            } else {
                bottomListdata = databean.getData();
                mAdapter = new CommonAdapter<HomeBotomListBean.DataBean>(this, bottomListdata, R.layout.item_home_gridview) {
                    @Override
                    public void convert(MyViewHolder holder, final int position) {
                        final HomeBotomListBean.DataBean dataBean = bottomListdata.get(position);
                        ImageView contentIv = (ImageView) holder.getView(R.id.iv_gridlable);
                        ImageOptions imageOptions = new ImageOptions.Builder()
                               // .setSize(DensityUtil.dip2px(120), DensityUtil.dip2px(120))//图片大小
                              //  .setRadius(DensityUtil.dip2px(5))//ImageView圆角半径
                               // .setCrop(true)// 如果ImageView的大小不是定义为wrap_content, 不要crop.
                                //.setImageScaleType(ImageView.ScaleType.CENTER_CROP)//缩放
                                .setLoadingDrawableId(R.mipmap.bg_loadimage)//加载中默认显示图片
                                .setUseMemCache(true)//设置使用缓存
                                .setFailureDrawableId(R.mipmap.bg_loadimage)//加载失败后默认显示图片
                                .setConfig( Bitmap.Config.ARGB_8888)
                                .build();
                        x.image().bind(contentIv, dataBean.getNvc_PicMain(),imageOptions);
                       // Glide.with(HomeWedShoppingActivity.this).load(dataBean.getNvc_PicMain()).placeholder(R.mipmap.bg_loadimage) .diskCacheStrategy(DiskCacheStrategy.SOURCE).into(contentIv);
                        holder.setText(R.id.tv_gridname, dataBean.getNvc_Name());
                        holder.setText(R.id.tv_gridcollection, String.valueOf(dataBean.getI_Collections()) + "人收藏");
                        holder.setText(R.id.tv_shopprice, "￥" + String.valueOf(dataBean.getDm_ShopPrice()));
                        holder.setText(R.id.tv_price, "￥" + String.valueOf(dataBean.getDm_Price()));
                        holder.getTextView(R.id.tv_price).getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中划线
                        holder.getTextView(R.id.tv_price).getPaint().setAntiAlias(true);//抗锯齿
                        holder.setOnClickListener(R.id.ll_home_left_pager, new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                // 点击进入详情界面
                                Intent intent = new Intent(HomeWedShoppingActivity.this, HomeProductdetailActivity.class);
                                intent.putExtra("productId", bottomListdata.get(position).getI_Id());
                                startActivity(intent);
                            }
                        });


                    }
                };
                mCommodityGv.setAdapter(mAdapter);
            }
            pageIndex++;

        }
    }

    //初始化上啦刷新
    public void initRefreshView() {
        //是否允许下拉刷新
        xRefreshView.setPullRefreshEnable(true);
        // 设置是否可以上拉加载
        xRefreshView.setPullLoadEnable(true);
        // 设置刷新完成以后，headerview固定的时间
        xRefreshView.setPinnedTime(1000);
        // 设置支持自动刷新
        xRefreshView.setAutoLoadMore(false);
        // 设置上次刷新的时间
        xRefreshView.restoreLastRefreshTime(lastRefreshTime);
        xRefreshView.setXRefreshViewListener(new XRefreshView.SimpleXRefreshListener() {
            public void onRefresh() {
                resetPageIndex();
                getListdata(categoryId, pageIndex, mCurrentOrder);
            }
            @Override
            public void onLoadMore(boolean isSlience) {
                getListdata(categoryId, pageIndex, mCurrentOrder);
            }
            @Override
            public void onRelease(float direction) {
                super.onRelease(direction);
            }
        });

    }


    @Override
    public void onError(ErrorBean errorBean) {
        xRefreshView.stopRefresh();
        xRefreshView.stopLoadMore();
        switch (errorBean.getErrorCode()) {
            case NONET:
                notifyViewLay(NODATA);
                break;
            default:
                CUtils.showDataErrToast(this);
        }
    }

    //显示窗体
    private void showOrderPopupWindow(View rootview) {
        //设置contentView
        View contentView = LayoutInflater.from(HomeWedShoppingActivity.this).inflate(R.layout.item_product_shoporder, null);

        wedshopRbtn = (RadioButton) contentView.findViewById(R.id.rbtn_defaultorder);
        wedshoeRbtn = (RadioButton) contentView.findViewById(R.id.rbtn_collectorder);
        wedlifeRbtn = (RadioButton) contentView.findViewById(R.id.rbtn_newreleasectorder);
        housethingRbtn = (RadioButton) contentView.findViewById(R.id.rbtn_priceuporder);
        jewelryRbtn = (RadioButton) contentView.findViewById(R.id.rbtn_priceorder);
        babythingRbtn = (RadioButton) contentView.findViewById(R.id.rbtn_third_right);
        mSet1Rbtn = (RadioButton) contentView.findViewById(R.id.rbtn_product_1);
        mSet2Rbtn = (RadioButton) contentView.findViewById(R.id.rbtn_product_2);
        mSet3Rbtn = (RadioButton) contentView.findViewById(R.id.rbtn_product_3);
        mSet4Rbtn = (RadioButton) contentView.findViewById(R.id.rbtn_product_4);

        mSet1Rbtn.setVisibility(View.VISIBLE);
        mSet2Rbtn.setVisibility(View.VISIBLE);
        mSet3Rbtn.setVisibility(View.VISIBLE);
        mSet4Rbtn.setVisibility(View.INVISIBLE);

        LinearLayout bottomLay = (LinearLayout) contentView.findViewById(R.id.lay_bottomLay);

        bottomLay.setVisibility(View.VISIBLE);
        housethingRbtn.setVisibility(View.VISIBLE);
        jewelryRbtn.setVisibility(View.VISIBLE);
        babythingRbtn.setVisibility(View.VISIBLE);
        housethingRbtn.setBackgroundColor(getResources().getColor(R.color.colorWhite));
        housethingRbtn.setBackgroundResource(R.drawable.common_item_select);

        wedshopRbtn.setText("婚纱礼服");
        wedshoeRbtn.setText("珠宝配饰");
        wedlifeRbtn.setText("家用电器");
        housethingRbtn.setText("护肤美体");
        jewelryRbtn.setText("户外运动");
        babythingRbtn.setText("婚礼用品");
        mSet1Rbtn.setText("母婴生活");
        mSet2Rbtn.setText("厨卫用品");
        mSet3Rbtn.setText("家居家装");

        wedshopRbtn.setOnCheckedChangeListener(HomeWedShoppingActivity.this);
        wedshoeRbtn.setOnCheckedChangeListener(HomeWedShoppingActivity.this);
        wedlifeRbtn.setOnCheckedChangeListener(HomeWedShoppingActivity.this);
        housethingRbtn.setOnCheckedChangeListener(HomeWedShoppingActivity.this);
        jewelryRbtn.setOnCheckedChangeListener(HomeWedShoppingActivity.this);
        babythingRbtn.setOnCheckedChangeListener(HomeWedShoppingActivity.this);
        mSet1Rbtn.setOnCheckedChangeListener(HomeWedShoppingActivity.this);
        mSet2Rbtn.setOnCheckedChangeListener(HomeWedShoppingActivity.this);
        mSet3Rbtn.setOnCheckedChangeListener(HomeWedShoppingActivity.this);


        wedshopRbtn.setOnClickListener(HomeWedShoppingActivity.this);
        wedshoeRbtn.setOnClickListener(HomeWedShoppingActivity.this);
        wedlifeRbtn.setOnClickListener(HomeWedShoppingActivity.this);
        housethingRbtn.setOnClickListener(HomeWedShoppingActivity.this);
        jewelryRbtn.setOnClickListener(HomeWedShoppingActivity.this);
        babythingRbtn.setOnClickListener(HomeWedShoppingActivity.this);
        mSet1Rbtn.setOnClickListener(HomeWedShoppingActivity.this);
        mSet2Rbtn.setOnClickListener(HomeWedShoppingActivity.this);
        mSet3Rbtn.setOnClickListener(HomeWedShoppingActivity.this);

        if (currentIndex != 0) {
            switch (currentIndex) {
                case 1:
                    wedshopRbtn.setChecked(true);

                    break;
                case 2:
                    wedshoeRbtn.setChecked(true);

                    break;
                case 3:
                    wedlifeRbtn.setChecked(true);

                    break;
                case 4:
                    housethingRbtn.setChecked(true);
                    break;
                case 5:
                    jewelryRbtn.setChecked(true);
                    break;
                case 6:
                    babythingRbtn.setChecked(true);
                    break;
                case 7:
                    mSet1Rbtn.setChecked(true);
                    break;
                case 8:
                    mSet2Rbtn.setChecked(true);
                    break;
                case 9:
                    mSet3Rbtn.setChecked(true);
                    break;
            }

        }

        contentView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mAreaPop.dismiss();
            }
        });

        mAreaPop = new PopupWindow(contentView, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);
        mAreaPop.setContentView(contentView);
        mAreaPop.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.whitetranslucenthalf2)));
        int height = contentView.getHeight() + mContentTitleLay.getHeight();
        //设置各个控件的点击响应
        mAreaPop.showAsDropDown(mContentTitleLay);
        mAreaPop.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
            }
        });


    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

        mPriceTv.setTextColor(getResources().getColor(R.color.colorFontGray1));
        mPriceOrderIv.setBackgroundResource(R.mipmap.order_normal);
        switch (buttonView.getId()) {
            case R.id.rbtn_defaultorder:

                if (isChecked) {
                    mDefaultorderTv.setText("婚纱礼服");
                    mDefaultorderTv.setTextColor(getResources().getColor(R.color.colorMainRed));
                    buttonView.setTextColor(getResources().getColor(R.color.colorWhite));

                    wedshoeRbtn.setChecked(false);
                    wedlifeRbtn.setChecked(false);
                    housethingRbtn.setChecked(false);
                    jewelryRbtn.setChecked(false);
                    babythingRbtn.setChecked(false);
                    mSet1Rbtn.setChecked(false);
                    mSet2Rbtn.setChecked(false);
                    mSet3Rbtn.setChecked(false);

                    currentIndex = 1;


                } else {
                    buttonView.setTextColor(getResources().getColor(R.color.colorFontGray1));
                }

                break;
            case R.id.rbtn_collectorder:
                if (isChecked) {
                    mDefaultorderTv.setText("珠宝配饰");
                    mDefaultorderTv.setTextColor(getResources().getColor(R.color.colorMainRed));

                    buttonView.setTextColor(getResources().getColor(R.color.colorWhite));
                    wedshopRbtn.setChecked(false);

                    wedlifeRbtn.setChecked(false);
                    housethingRbtn.setChecked(false);
                    jewelryRbtn.setChecked(false);
                    babythingRbtn.setChecked(false);
                    mSet1Rbtn.setChecked(false);
                    mSet2Rbtn.setChecked(false);
                    mSet3Rbtn.setChecked(false);

                    currentIndex = 2;

                } else {
                    buttonView.setTextColor(getResources().getColor(R.color.colorFontGray1));
                }


                break;
            case R.id.rbtn_newreleasectorder:
                if (isChecked) {
                    mDefaultorderTv.setText("家用电器");
                    mDefaultorderTv.setTextColor(getResources().getColor(R.color.colorMainRed));

                    buttonView.setTextColor(getResources().getColor(R.color.colorWhite));
                    wedshopRbtn.setChecked(false);
                    wedshoeRbtn.setChecked(false);

                    housethingRbtn.setChecked(false);
                    jewelryRbtn.setChecked(false);
                    babythingRbtn.setChecked(false);
                    mSet1Rbtn.setChecked(false);
                    mSet2Rbtn.setChecked(false);
                    mSet3Rbtn.setChecked(false);

                    currentIndex = 3;

                } else {
                    buttonView.setTextColor(getResources().getColor(R.color.colorFontGray1));
                }

                break;
            case R.id.rbtn_priceuporder:
                if (isChecked) {
                    mDefaultorderTv.setText("护肤美体");
                    mDefaultorderTv.setTextColor(getResources().getColor(R.color.colorMainRed));

                    buttonView.setTextColor(getResources().getColor(R.color.colorWhite));
                    wedshopRbtn.setChecked(false);
                    wedshoeRbtn.setChecked(false);
                    wedlifeRbtn.setChecked(false);

                    jewelryRbtn.setChecked(false);
                    babythingRbtn.setChecked(false);
                    mSet1Rbtn.setChecked(false);
                    mSet2Rbtn.setChecked(false);
                    mSet3Rbtn.setChecked(false);

                    currentIndex = 4;

                } else {
                    buttonView.setTextColor(getResources().getColor(R.color.colorFontGray1));
                }

                break;
            case R.id.rbtn_priceorder:
                if (isChecked) {
                    mDefaultorderTv.setText("户外运动");
                    mDefaultorderTv.setTextColor(getResources().getColor(R.color.colorMainRed));

                    buttonView.setTextColor(getResources().getColor(R.color.colorWhite));
                    wedshopRbtn.setChecked(false);
                    wedshoeRbtn.setChecked(false);
                    wedlifeRbtn.setChecked(false);
                    housethingRbtn.setChecked(false);

                    babythingRbtn.setChecked(false);
                    mSet1Rbtn.setChecked(false);
                    mSet2Rbtn.setChecked(false);
                    mSet3Rbtn.setChecked(false);

                    currentIndex = 5;

                } else {
                    buttonView.setTextColor(getResources().getColor(R.color.colorFontGray1));
                }

                break;
            case R.id.rbtn_third_right:
                if (isChecked) {
                    mDefaultorderTv.setText("婚礼用品");
                    mDefaultorderTv.setTextColor(getResources().getColor(R.color.colorMainRed));

                    buttonView.setTextColor(getResources().getColor(R.color.colorWhite));
                    wedshopRbtn.setChecked(false);
                    wedshoeRbtn.setChecked(false);
                    wedlifeRbtn.setChecked(false);
                    housethingRbtn.setChecked(false);
                    jewelryRbtn.setChecked(false);
                    mSet1Rbtn.setChecked(false);
                    mSet2Rbtn.setChecked(false);
                    mSet3Rbtn.setChecked(false);

                    currentIndex = 6;

                } else {
                    buttonView.setTextColor(getResources().getColor(R.color.colorFontGray1));
                }

                break;
            case R.id.rbtn_product_1:
                if (isChecked) {
                    mDefaultorderTv.setText("母婴生活");
                    mDefaultorderTv.setTextColor(getResources().getColor(R.color.colorMainRed));

                    buttonView.setTextColor(getResources().getColor(R.color.colorWhite));
                    wedshopRbtn.setChecked(false);
                    wedshoeRbtn.setChecked(false);
                    wedlifeRbtn.setChecked(false);
                    housethingRbtn.setChecked(false);
                    jewelryRbtn.setChecked(false);
                    babythingRbtn.setChecked(false);
                    mSet2Rbtn.setChecked(false);
                    mSet3Rbtn.setChecked(false);

                    currentIndex = 7;

                } else {
                    buttonView.setTextColor(getResources().getColor(R.color.colorFontGray1));
                }

                break;
            case R.id.rbtn_product_2:
                if (isChecked) {
                    mDefaultorderTv.setText("厨卫用品");
                    mDefaultorderTv.setTextColor(getResources().getColor(R.color.colorMainRed));

                    buttonView.setTextColor(getResources().getColor(R.color.colorWhite));
                    wedshopRbtn.setChecked(false);
                    wedshoeRbtn.setChecked(false);
                    wedlifeRbtn.setChecked(false);
                    housethingRbtn.setChecked(false);
                    jewelryRbtn.setChecked(false);
                    babythingRbtn.setChecked(false);
                    mSet1Rbtn.setChecked(false);
                    mSet3Rbtn.setChecked(false);

                    currentIndex = 8;

                } else {
                    buttonView.setTextColor(getResources().getColor(R.color.colorFontGray1));
                }

                break;
            case R.id.rbtn_product_3:
                if (isChecked) {
                    mDefaultorderTv.setText("家居家装");
                    mDefaultorderTv.setTextColor(getResources().getColor(R.color.colorMainRed));

                    buttonView.setTextColor(getResources().getColor(R.color.colorWhite));
                    wedshopRbtn.setChecked(false);
                    wedshoeRbtn.setChecked(false);
                    wedlifeRbtn.setChecked(false);
                    housethingRbtn.setChecked(false);
                    jewelryRbtn.setChecked(false);
                    babythingRbtn.setChecked(false);
                    mSet1Rbtn.setChecked(false);
                    mSet2Rbtn.setChecked(false);

                    currentIndex = 9;

                } else {
                    buttonView.setTextColor(getResources().getColor(R.color.colorFontGray1));
                }

                break;

        }

    }
    private void freshTextview(TextView view) {
        Resources resources = getResources();
        if (view.getCurrentTextColor() == resources.getColor(R.color.colorMainRed)) {
            view.setTextColor(resources.getColor(R.color.colorFontGray1));
        } else {
            view.setTextColor(resources.getColor(R.color.colorMainRed));
        }
    }
    public void showLoginDialog() {
        final ConfirmLoginDialog confirmDialog = new ConfirmLoginDialog(this,   "亲，需要登录哦~", "去登录",  "取消", R.layout.pop_tologin);
        confirmDialog.show();
        confirmDialog.setClicklistener(new ConfirmLoginDialog.ClickListenerInterface() {
            @Override
            public void doConfirm() {
                Intent intent = new Intent(HomeWedShoppingActivity.this, LoginActivity.class);
                intent.putExtra("isCanBack", true);
                HomeWedShoppingActivity.this.startActivityForResult(intent,REQUEST_LOGIN_CODE);
                confirmDialog.dismiss();
            }

            @Override
            public void doCancel() {
                confirmDialog.dismiss();
            }
        });
    }

    private void resetPageIndex() {
        pageIndex = 1;
    }

    private void notifyViewLay(int state) {
        switch (state) {
            case HAVEDATA:
                mProgressLay.setVisibility(View.GONE);
                if (mContentLay.isShown()) {
                    return;
                } else {
                    mContentLay.setVisibility(View.VISIBLE);
                }
                mContentLay.setVisibility(View.VISIBLE);
                mNoNetLay.setVisibility(View.GONE);

                break;
            case NODATA:
                mProgressLay.setVisibility(View.GONE);
                mContentLay.setVisibility(View.GONE);
                mNoNetLay.setVisibility(View.VISIBLE);
                break;
            case DATAERROR:

                break;
            case LOADINGDATA:
                mProgressLay.setVisibility(View.VISIBLE);
                break;
        }
    }
}
